package com.iflyteck.boot;

import com.iflyteck.client.ClientUtils;
import com.iflyteck.client.RPCConsumer;
import com.iflyteck.pojo.RpcRequest;
import com.iflyteck.service.IUserService;

import java.util.UUID;

public class ConsumerBoot {

    // 参数定义
    // private static final String PROVIDER_NAME = "IUserService#sayHello#";
    // private static final RpcRequest rpcRequest = new RpcRequest();

    public static void main(String[] args) throws Exception {
        // 加载zookeeper上的服务节点信息
        ClientUtils.loadZkProvider();

        // 请求构建实体
        RpcRequest rpcRequest = new RpcRequest();
        rpcRequest.setRequestId(UUID.randomUUID().toString());
        rpcRequest.setClassName("userService");
        rpcRequest.setMethodName("sayHello");
        rpcRequest.setParameterTypes(new Class<?>[]{String.class});
        rpcRequest.setParameters(new Object[]{"are you ok?"});
        // 创建代理对象
        IUserService proxy = (IUserService)RPCConsumer.createProxy(IUserService.class, rpcRequest);
        // 循环给服务器写数据
        while (true) {
            String res = proxy.sayHello("are you ok!!");
            System.out.println(res);
            Thread.sleep(2000);
        }
    }
}
